<% content_for :stylesheet_head do %>
        <style>
          .bu,button.button,tr td button {
                padding: 2px 10px;
                margin: 0px 10px;
                background: #009bce;
                border-radius: 4px;
                border: 1px;
                color: #fff;
            }
        </style>
<% end %>
<!-- 新增隐藏框 -->
<div class="modal fade" id="Modal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="ModalLabel">酒店新增</h4>
      </div>
        <%= form_tag('/hotel/update_new', method: :post, :class=>"form-horizontal") do %>
              <div class="modal-body">
                      <table class="table  list_table">
                        <tbody>
                                <tr>
                                      <td>
                                          酒店名称:<span style="color: red">*</span>
                                      </td>
                                      <td>
                                       <%= text_field  :hotel,:name,:class => "form-control",:id=>'hotel_new_name' %>
                                      </td>                                    
                                </tr>                                
                                <tr>
                                  <td colspan="2">
                                      <div id="shadow" style="display: none;">
                                        <div id="information"><p style="color: red;font-weight: bold;"></p></div>
                                      </div>
                                  </td>
                              </tr>
                        </tbody>
                      </table>
             </div>

            <div class="modal-footer">
                <button type="reset" class="btn btn-default" data-dismiss="modal">
                             关闭
                        </button>
                <button type="submit" class="btn btn-primary" onclick ="return Check_new(0);" >
                             提交
                        </button>
              </div>
          </div>
   <% end %>
     <div class="WhereToLinks"></div>
  </div>
</div>
<!-- 新增隐藏框结束 -->
<!-- 修改隐藏框 -->
<div class="modal fade" id="Modal2" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="ModalLabel">酒店修改</h4>
      </div>
        <%= form_tag('/hotel/update_edit', method: :post, :class=>"form-horizontal") do %>
              <div class="modal-body">
                      <table class="table  list_table">
                        <tbody>
                                <tr>
                                      <td>
                                          酒店名称:<span style="color: red">*</span>
                                      </td>
                                      <td>
                                       <%= text_field  :hotel,:name,:class => "form-control",:id=>'hotel_new_name_edit' %>
                                       <%= hidden_field :hotel,:id ,:id=>'hotel_id'%>
                                      </td>                                    
                                </tr>                                
                                <tr>
                                  <td colspan="2">
                                      <div id="shadow2" style="display: none;">
                                        <div id="information2"><p style="color: red;font-weight: bold;"></p></div>
                                      </div>
                                  </td>
                              </tr>
                        </tbody>
                      </table>
             </div>

            <div class="modal-footer">
                <button type="reset" class="btn btn-default" data-dismiss="modal">
                             关闭
                        </button>
                <button type="submit" class="btn btn-primary" onclick ="return Check_new(1);" >
                             提交
                        </button>
              </div>
          </div>
   <% end %>
     <div class="WhereToLinks"></div>
  </div>
</div>
<!-- 修改隐藏框结束 -->
    <div class="listFilter" style="margin: 20px;">
      <h2>酒店资料</h2>
      <div class="divider"></div>
       <%= form_for_filterrific @filterrific do |f| %>
            <table style="width: 50%;" class="list_table">
                  <tbody>
                    <tr>
                      <td>酒店名称:</td>
                      <td><%= f.text_field :with_name %></td>
                      <td><%= f.submit "查询", :class=>"button" %></td>
                      <td>
                        <div class="bu" data-toggle="modal" data-target="#Modal" onclick="cl()"  style="min-width: 100px;text-align: center;float: right;cursor: pointer;">
                          新增
                        </div>                        
                      </td>
                    </tr>
                  </tbody>
            </table>
        <% end %>
      <div class="list_table"  >
        <table class="bb list_table"  cellspacing="0" style="text-align:left" >
          <thead>
            <tr>
              <th width='1%'>序号</th>
              <th width='1%'>酒店名称</th>
              <th width='1%'>创建时间</th>
               <th width='1%'>操作</th>
            </tr>
          </thead>
          <tbody id="tbody">
          <%  if @hotels != nil
             odd_or_even = 0
             tmp=0
            @hotels.each do |hotels|
               tmp = tmp+1
          -%>
                  <tr class="odd_row">
                      <td><%= h(tmp) %></td>
                      <td><%= hotels.name %></td>
                      <td><%= hotels.created_at.strftime("%Y-%m-%d %H:%M:%S") %></td>
                      <td >                  
                          <%= link_to "删除",hotel_path(hotels),{style:"color:red",method: :delete, data: { confirm: '确认删除酒店信息?' } } %>                
                            <a href="javascript:" data-toggle="modal" data-target="#Modal2" onclick="edit_load(<%=hotels.id%>);" style="color:red">
                           修改
                         </a>
                          <%= link_to "酒店资料",edit_hotel_path(hotels.id),{style:"color:red" }%> 
                    </td>
                 </tr>
            <% end %>
            <% end %>
          <tr>
            <td colspan="4">
               <%= will_paginate(@hotels ,:previous_label=>'上一页',:next_label=>'下一页')  %>
            </td>
         </tr>
          </tbody>
        </table>
        <div class="WhereToLinks"></div>
      </div>
    </div>
    <% content_for :javascript_head do %>  
       <script type="text/javascript">
                      function edit_load(id){                             
                               $("form[action='/hotel/update_edit']")[0].reset();
                               var url="/hotel/hotel_ajax_edit_load?a="+id;                                
                                $.ajax({url:url,
                                        async:false,
                                        type: "get",
                                        success:function(r){                          
                                              aa=JSON.parse(r);
                                              if ( aa!=null   )   
                                                  { 
                                                     $("#hotel_new_name_edit").val(aa.name);                      
                                                     $("#hotel_id").val(aa.id);
                                                  } 
                                              else
                                                 {  alert("数据错误请刷新!");  }
                                                          }
                                      })
                      }
                      function cl(){
                          $("form[action='/hotel/update_new']")[0].reset();
                      }
                      function err_message(text,id){
                                  if (id==2)
                                   {
                                     $("#information2 p").html(text);
                                     $("#shadow2").fadeIn().delay(2000).fadeOut();
                                   }
                                  else
                                   {
                                     $("#information p").html(text);
                                     $("#shadow").fadeIn().delay(2000).fadeOut();
                                   }                                   
                               }

                     function Check_new(id){
                               if (id==0)    //新增
                                   { 
                                     var  hotel_name=document.getElementById('hotel_new_name');
                                     hotel_name.value=hotel_name.value.trim()
                                     hotel_id=0
                                   }
                               else      //修改
                                   { 
                                     var  hotel_name=document.getElementById('hotel_new_name_edit');
                                     var  hotel=document.getElementById('hotel_id');
                                     hotel_name.value=hotel_name.value.trim() 
                                     hotel.value=hotel.value.trim()  
                                     hotel_id=hotel.value                             
                                   }
                               var a=hotel_name.value ;
                               if ( a=='' )
                                { 
                                  if (id==0)    //新增
                                   { err_message("请输入酒店名称！");}
                                  else
                                   { err_message("请输入酒店名称！",2);} 
                                  hotel_name.focus();
                                  return false  ;
                                }
                                var url="/hotel/hotel_ajax?a="+a+"&id="+hotel_id;
                                var ref=1
                                $.ajax({url:url,
                                        async:false,
                                        type: "get",
                                        success:function(r){                          
                                              aa=JSON.parse(r);
                                              if ( aa=='0'   )   //不让提交
                                                  { 
                                                    if (id==0)    //新增
                                                       { 
                                                         err_message("酒店名称已存在！");
                                                         hotel_name.value="" ;
                                                       }
                                                    else
                                                       { 
                                                         err_message("酒店名称已存在！",2);
                                                         hotel_name.value="" ;
                                                        } 
                                                    hotel_name.focus();
                                                    ref=0;
                                                  } 
                                                           }
                                      })
                                if (ref==0)
                                 {return false;}
                       }
        </script>
    <% end %>
